package com.youngking.guns.modular.auth.validator.impl;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.youngking.guns.modular.auth.validator.IReqValidator;
import com.youngking.guns.modular.auth.validator.dto.Credence;
import com.youngking.guns.modular.system.model.User;
import com.youngking.guns.modular.system.model.Wxuserinfo;
import com.youngking.guns.modular.system.service.IUserService;
import com.youngking.guns.modular.wxuserinfo.service.IWxuserinfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.weixin4j.Weixin;
import org.weixin4j.WeixinException;

/**
 * 直接验证账号密码是不是admin
 *
 * @author fengshuonan
 * @date 2017-08-23 12:34
 */
@Service
public class SimpleValidator implements IReqValidator {

    @Autowired
    private IWxuserinfoService wxuserinfoService;

    @Override
    public LoginP validate(Credence credence) {
        LoginP loginP = new LoginP();
        String vid  = credence.getCVid();
        Weixin weixin =new Weixin();
        EntityWrapper ew = new EntityWrapper();
        ew.setEntity(new Wxuserinfo());
        ew.where("id = {0}",vid);
        Wxuserinfo wxuserinfo = wxuserinfoService.selectOne(ew);
        if(wxuserinfo!=null){
            loginP.setWxuserinfo(wxuserinfo);
            loginP.setIspass(true);
            return  loginP;
        }else {
            loginP.setIspass(true);
            return loginP;
        }
    }
}
